home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH9 / SRC / OBLIQUE.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-11-16  |  5.4 KB  |  184 lines

  1. VERSION 4.00
  2. Begin VB.Form ObliqueForm 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H00C0C0C0&
  5.    Caption         =   "Oblique Projections"
  6.    ClientHeight    =   2835
  7.    ClientLeft      =   975
  8.    ClientTop       =   2100
  9.    ClientWidth     =   7470
  10.    BeginProperty Font 
  11.       name            =   "MS Sans Serif"
  12.       charset         =   1
  13.       weight          =   700
  14.       size            =   8.25
  15.       underline       =   0   'False
  16.       italic          =   0   'False
  17.       strikethrough   =   0   'False
  18.    EndProperty
  19.    ForeColor       =   &H80000008&
  20.    Height          =   3525
  21.    KeyPreview      =   -1  'True
  22.    Left            =   915
  23.    LinkTopic       =   "Form1"
  24.    ScaleHeight     =   2835
  25.    ScaleWidth      =   7470
  26.    Top             =   1470
  27.    Width           =   7590
  28.    Begin VB.PictureBox Pict 
  29.       AutoRedraw      =   -1  'True
  30.       Height          =   2415
  31.       Index           =   2
  32.       Left            =   5040
  33.       ScaleHeight     =   -6
  34.       ScaleLeft       =   -3
  35.       ScaleMode       =   0  'User
  36.       ScaleTop        =   3
  37.       ScaleWidth      =   6
  38.       TabIndex        =   2
  39.       Top             =   0
  40.       Width           =   2415
  41.    End
  42.    Begin VB.PictureBox Pict 
  43.       AutoRedraw      =   -1  'True
  44.       Height          =   2415
  45.       Index           =   1
  46.       Left            =   2520
  47.       ScaleHeight     =   -6
  48.       ScaleLeft       =   -3
  49.       ScaleMode       =   0  'User
  50.       ScaleTop        =   3
  51.       ScaleWidth      =   6
  52.       TabIndex        =   1
  53.       Top             =   0
  54.       Width           =   2415
  55.    End
  56.    Begin VB.PictureBox Pict 
  57.       AutoRedraw      =   -1  'True
  58.       Height          =   2415
  59.       Index           =   0
  60.       Left            =   0
  61.       ScaleHeight     =   -6
  62.       ScaleLeft       =   -3
  63.       ScaleMode       =   0  'User
  64.       ScaleTop        =   3
  65.       ScaleWidth      =   6
  66.       TabIndex        =   0
  67.       Top             =   0
  68.       Width           =   2415
  69.    End
  70.    Begin VB.Label Label1 
  71.       Alignment       =   2  'Center
  72.       Caption         =   "Cabinet"
  73.       Height          =   255
  74.       Index           =   2
  75.       Left            =   5040
  76.       TabIndex        =   5
  77.       Top             =   2520
  78.       Width           =   2415
  79.    End
  80.    Begin VB.Label Label1 
  81.       Alignment       =   2  'Center
  82.       Caption         =   "Cavalier"
  83.       Height          =   255
  84.       Index           =   1
  85.       Left            =   2520
  86.       TabIndex        =   4
  87.       Top             =   2520
  88.       Width           =   2415
  89.    End
  90.    Begin VB.Label Label1 
  91.       Alignment       =   2  'Center
  92.       Caption         =   "Orthographic"
  93.       Height          =   255
  94.       Index           =   0
  95.       Left            =   0
  96.       TabIndex        =   3
  97.       Top             =   2520
  98.       Width           =   2415
  99.    End
  100.    Begin VB.Menu mnuFile 
  101.       Caption         =   "&File"
  102.       Begin VB.Menu mnuFileExit 
  103.          Caption         =   "E&xit"
  104.       End
  105.    End
  106. Attribute VB_Name = "ObliqueForm"
  107. Attribute VB_Creatable = False
  108. Attribute VB_Exposed = False
  109. Option Explicit
  110. ' Location of viewing eye.
  111. Dim EyeR As Single
  112. Dim EyeTheta As Single
  113. Dim EyePhi As Single
  114. ' Location of focus point.
  115. Const FocusX = 0#
  116. Const FocusY = 0#
  117. Const FocusZ = 0#
  118. Dim Projector(1 To 4, 1 To 4) As Single
  119. Dim CavProj(1 To 4, 1 To 4) As Single
  120. Dim CabProj(1 To 4, 1 To 4) As Single
  121. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  122. Const Dtheta = PI / 20
  123.     Select Case KeyCode
  124.         Case vbKeyLeft
  125.             EyeTheta = EyeTheta - Dtheta
  126.         
  127.         Case vbKeyRight
  128.             EyeTheta = EyeTheta + Dtheta
  129.         
  130.         Case vbKeyUp
  131.             EyePhi = EyePhi - Dtheta
  132.         
  133.         Case vbKeyDown
  134.             EyePhi = EyePhi + Dtheta
  135.         
  136.         Case Else
  137.             Exit Sub
  138.     End Select
  139.     m3PProject Projector, m3Perspective, EyeR, EyePhi, EyeTheta, FocusX, FocusY, FocusZ, 0, 1, 0
  140.     TransformAllData Projector
  141.     DrawAllData Pict(0), ForeColor, True
  142. End Sub
  143. Private Sub Form_Load()
  144.     ' Initialize the eye position.
  145.     EyeR = 3
  146.     EyeTheta = PI * 0.4
  147.     EyePhi = PI * 0.1
  148.     ' Create the data.
  149.     CreateData
  150.     ' Create the projection matrices.
  151.     m3PProject Projector, m3Perspective, EyeR, EyePhi, EyeTheta, FocusX, FocusY, FocusZ, 0, 1, 0
  152.     m3ObliqueXY CavProj, 1#, PI / 6
  153.     m3ObliqueXY CabProj, 0.5, PI / 6
  154.     ' Project and draw the data.
  155.     TransformAllData Projector
  156.     DrawAllData Pict(0), ForeColor, True
  157.     TransformAllData CavProj
  158.     DrawAllData Pict(1), ForeColor, True
  159.     TransformAllData CabProj
  160.     DrawAllData Pict(2), ForeColor, True
  161. End Sub
  162. Sub CreateData()
  163.     ' Create the axes.
  164.     MakeSegment 0, 0, 0, 3, 0, 0    ' X axis.
  165.     MakeSegment 0, 0, 0, 0, 3, 0    ' Y axis.
  166.     MakeSegment 0, 0, 0, 0, 0, 3    ' Z axis.
  167.     ' Create the object to display.
  168.     MakeSegment 0, 0, 0, 2, 0, 0
  169.     MakeSegment 2, 0, 0, 2, 2, 0
  170.     MakeSegment 2, 2, 0, 0, 2, 0
  171.     MakeSegment 0, 2, 0, 0, 0, 0
  172.     MakeSegment 0, 0, 2, 2, 0, 2
  173.     MakeSegment 2, 0, 2, 2, 2, 2
  174.     MakeSegment 2, 2, 2, 0, 2, 2
  175.     MakeSegment 0, 2, 2, 0, 0, 2
  176.     MakeSegment 0, 0, 0, 0, 0, 2
  177.     MakeSegment 2, 0, 0, 2, 0, 2
  178.     MakeSegment 2, 2, 0, 2, 2, 2
  179.     MakeSegment 0, 2, 0, 0, 2, 2
  180. End Sub
  181. Private Sub mnuFileExit_Click()
  182.     Unload Me
  183. End Sub
  184.